package com.jiayi.web.controller.cms;

import com.jiayi.api.JiayiAboutUsService;
import com.jiayi.common.annotation.Log;
import com.jiayi.common.core.domain.AjaxResult;
import com.jiayi.common.core.page.TableDataInfo;
import com.jiayi.common.developutil.ConvertUtils;
import com.jiayi.common.enums.BusinessType;
import com.jiayi.data.converter.JiayiAboutUsConverter;
import com.jiayi.data.entity.CmsAboutUsClass;
import com.jiayi.data.entity.request.JiayiAboutUsRequest;
import com.jiayi.data.entity.request.JiayiAboutUsSearchPageRequest;
import com.jiayi.data.entity.request.JiayiAboutUsSearchRequest;
import com.jiayi.data.entity.schema.JiayiAboutUs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 关于我们配置Controller
 *
 * @author zzx
 * @date 2024-11-26
 */
@RestController
@RequestMapping("/cms/jiayi_about_us")
public class JiayiAboutUsController {
    @Autowired
    private JiayiAboutUsService jiayiAboutUsService;

    @Autowired
    private JiayiAboutUsConverter jiayiAboutUsconverter;

    /**
     * 查询关于我们配置列表 分页
     */
    @PreAuthorize("@ss.hasPermi('cms:jiayi_about_us:list')")
    @PostMapping("/listPage")
    public TableDataInfo listPage(@RequestBody JiayiAboutUsSearchPageRequest request) {
        return jiayiAboutUsService.selectJiayiAboutUsList(request);
    }


    /**
     * 查询关于我们配置列表 不分页
     */
    @PreAuthorize("@ss.hasPermi('cms:jiayi_about_us:list')")
    @PostMapping("/list")
    public AjaxResult list(@RequestBody JiayiAboutUsSearchRequest request) {
        List<JiayiAboutUs> list = jiayiAboutUsService.selectJiayiAboutUsList(request);
        return AjaxResult.success(ConvertUtils.convert(list, jiayiAboutUsconverter::convertToJiayiAboutUsDTO));
    }

    /**
     * 导出关于我们配置列表
     */
    @PreAuthorize("@ss.hasPermi('cms:jiayi_about_us:export')")
    @Log(title = "关于我们配置" , businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@RequestBody JiayiAboutUsSearchRequest request, HttpServletResponse response) {
        jiayiAboutUsService.export(request, response);
    }

    /**
     * 获取关于我们配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:jiayi_about_us:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(jiayiAboutUsService.selectJiayiAboutUsById(id));
    }


    /**
     * 新增关于我们配置
     */
    @PreAuthorize("@ss.hasPermi('cms:jiayi_about_us:add')")
    @Log(title = "关于我们配置" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JiayiAboutUsRequest request) {
        return AjaxResult.toAjax(jiayiAboutUsService.insertJiayiAboutUs(request));
    }

    /**
     * 修改关于我们配置
     */
    @PreAuthorize("@ss.hasPermi('cms:jiayi_about_us:edit')")
    @Log(title = "关于我们配置" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JiayiAboutUsRequest request) {
        return AjaxResult.toAjax(jiayiAboutUsService.updateJiayiAboutUs(request));
    }

    /**
     * 删除关于我们配置
     */
    @PreAuthorize("@ss.hasPermi('cms:jiayi_about_us:remove')")
    @Log(title = "关于我们配置" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return AjaxResult.toAjax(jiayiAboutUsService.deleteJiayiAboutUsByIds(ids));
    }

    /**
     * 获取关于我们配置详细信息 - 首页图片
     */
    @PreAuthorize("@ss.hasPermi('cms:jiayi_about_us:query')")
    @GetMapping(value = "home-image")
    public AjaxResult getInfoHomeImage() {
        return AjaxResult.success(jiayiAboutUsService.getInfoByKey("home_image",null));
    }

    /**
     * 获取关于我们配置详细信息 - 公司简介
     */
    @PreAuthorize("@ss.hasPermi('cms:jiayi_about_us:query')")
    @GetMapping(value = "/company-profile")
    public AjaxResult getInfoCompanyProfile() {
        return AjaxResult.success(jiayiAboutUsService.getInfoByKey("company_profile",null));
    }

    /**
     * 获取关于我们配置详细信息 - 发展历程
     */
    @PreAuthorize("@ss.hasPermi('cms:jiayi_about_us:query')")
    @GetMapping(value = "/dev-history")
    public AjaxResult getInfoDevHistory() {
        return AjaxResult.success(jiayiAboutUsService.getInfoByKey("dev_history",null));
    }

    /**
     * 获取关于我们配置详细信息 - 资质荣誉
     */
    @PreAuthorize("@ss.hasPermi('cms:jiayi_about_us:query')")
    @PostMapping(value = "/company-honor")
    public AjaxResult getInfoCompanyHonor(@RequestBody CmsAboutUsClass.CompanyHonor companyHonor) {
        return AjaxResult.success(jiayiAboutUsService.getInfoByKey("company_honor",companyHonor));
    }

    /**
     * 获取关于我们配置详细信息 - 联系我们
     */
    @PreAuthorize("@ss.hasPermi('cms:jiayi_about_us:query')")
    @GetMapping(value = "/call-us")
    public AjaxResult getInfoCallUs() {
        return AjaxResult.success(jiayiAboutUsService.getInfoByKey("call_us",null));
    }
}
